package momo.multitree.algo;

import momo.multitree.structure.*;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class LatencyShortestPath extends ModifiedDijkstra {
	
	private Log log = LogFactory.getLog(CostShortestPath.class);
	
	public Tree optimumTree(Graph graph)
	{
		Node[] nodes = graph.getNodes().toArray(new Node[0]) ;
		if ( nodes.length == 0 )
			return null;
		
		Tree initTree = optimumTree(graph, nodes[0]);
		for(int i=1; i<nodes.length; i++)
		{
			Tree nextTree = optimumTree(graph, nodes[i]);
			if ( initTree.compWeightedLatency() > nextTree.compWeightedLatency() )
				initTree = nextTree;
		}
		return initTree;
	}

	public double calObjCost(LinkedHashSet<Node> S, Node node,
			LinkedHashSet<Edge> Et, Edge edgeToAdd,
			LinkedHashMap<Node, Double> labels) {
		
		Node inTree = null;
		if (edgeToAdd.getHeadNode().equals(node))
			inTree = edgeToAdd.getTailNode();
		else
			inTree = edgeToAdd.getHeadNode();
		
		double currLatency = labels.get(inTree);
		
		double adjLatency = currLatency + edgeToAdd.getLatency(inTree);
		
		return adjLatency;
	}

}
